package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.PaypalConfigMapper;
import com.ruoyi.system.domain.PaypalConfig;
import com.ruoyi.system.service.IPaypalConfigService;

/**
 * PayPal配置Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-13
 */
@Service
public class PaypalConfigServiceImpl implements IPaypalConfigService {
    @Autowired
    private PaypalConfigMapper paypalConfigMapper;

    /**
     * 查询PayPal配置
     *
     * @param id PayPal配置主键
     * @return PayPal配置
     */
    @Override
    public PaypalConfig selectPaypalConfigById(Long id) {
        return paypalConfigMapper.selectPaypalConfigById(id);
    }

    @Override
    public PaypalConfig selectPaypalConfig() {
        return paypalConfigMapper.selectPaypalConfig();
    }

    /**
     * 查询PayPal配置列表
     *
     * @param paypalConfig PayPal配置
     * @return PayPal配置
     */
    @Override
    public List<PaypalConfig> selectPaypalConfigList(PaypalConfig paypalConfig) {
        return paypalConfigMapper.selectPaypalConfigList(paypalConfig);
    }

    /**
     * 新增PayPal配置
     *
     * @param paypalConfig PayPal配置
     * @return 结果
     */
    @Override
    public int insertPaypalConfig(PaypalConfig paypalConfig) {
        paypalConfig.setCreateTime(DateUtils.getNowDate());
        String baseUrl = paypalConfig.getSandboxMode().equals("1")
                ? "https://www.sandbox.paypal.com"
                : "https://www.paypal.com";
        paypalConfig.setPaymentUrl(baseUrl);
        return paypalConfigMapper.insertPaypalConfig(paypalConfig);
    }

    /**
     * 修改PayPal配置
     *
     * @param paypalConfig PayPal配置
     * @return 结果
     */
    @Override
    public int updatePaypalConfig(PaypalConfig paypalConfig) {
        paypalConfig.setUpdateTime(DateUtils.getNowDate());
        String baseUrl = paypalConfig.getSandboxMode().equals("1")
                ? "https://www.sandbox.paypal.com"
                : "https://www.paypal.com";
        paypalConfig.setPaymentUrl(baseUrl);
        return paypalConfigMapper.updatePaypalConfig(paypalConfig);
    }

    /**
     * 批量删除PayPal配置
     *
     * @param ids 需要删除的PayPal配置主键
     * @return 结果
     */
    @Override
    public int deletePaypalConfigByIds(Long[] ids) {
        return paypalConfigMapper.deletePaypalConfigByIds(ids);
    }

    /**
     * 删除PayPal配置信息
     *
     * @param id PayPal配置主键
     * @return 结果
     */
    @Override
    public int deletePaypalConfigById(Long id) {
        return paypalConfigMapper.deletePaypalConfigById(id);
    }
}
